<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>微博详情页面</h1>
    <h3>{{weibo.nick}}:{{weibo.content}}</h3>
    <p style="color: #666">{{weibo.created}}</p>
    <img v-for="url in weibo.urlsArr" :src="url" width="100" alt="">
    <hr>
    <input type="text" v-model="comment.content" placeholder="说点儿啥...">
    <input type="button" value="发表评论" @click="insert()">
    <div v-for="comment in arr">
        <h5>{{comment.nick}}评论说:{{comment.content}}</h5>
    </div>
</div>
<!--引入Vue框架-->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!--引入Axios框架-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            weibo:{},
            comment:{content:"",weiboId:""},
            arr:[]
        },
        methods:{
            insert(){
                //在评论对象中添加微博id
                v.comment.weiboId=v.weibo.id;
                //发出评论请求
                axios.post("/comment/insert",v.comment).then(function (response) {
                   if (response.data==1){
                       alert("评论完成!")
                       location.reload();
                   }else{
                       alert("请先登录!")
                       location.href = "/login.html";
                   }
                })
            }
        },
        created:function () {
            //通过地址栏中的id 查询微博信息
            axios.get("/weibo/selectById"+location.search).then(function (response) {
                v.weibo = response.data;
                v.weibo.urlsArr = v.weibo.urls.split(",");
            })
            //通过当前页面显示的微博id查询相关评论
            axios.get("/comment/selectByWeiboId"+location.search)
                .then(function (response) {
                v.arr = response.data;
            })
        }
    })
</script>
</body>
</html>